/*
 *	name:		VOICE68.cpp
 *	version:	1.0
 *	Author:		doudad <doudad@qq.com>
 *	Date:		2023-04-27
 *	Description:	VOICE68 library for New MP3 board
 */

#include "Voice68.h"
#include"Arduino.h" 

VOICE68::VOICE68(uint8_t _rst_pin, uint8_t _data_pin, uint8_t _busy_pin)
{
	rst_pin = _rst_pin;
	data_pin = _data_pin;
	busy_pin = _busy_pin;
	pinMode(rst_pin, OUTPUT);
	pinMode(data_pin, OUTPUT);
	pinMode(busy_pin, INPUT);
	
}

/*
VOICE68::~VOICE68()
{
	disattach();
}	
*/	

void VOICE68::play (uint8_t num)
{
	digitalWrite(rst_pin,LOW);
	delayMicroseconds(200);
	digitalWrite(rst_pin,HIGH);
	delayMicroseconds(100);
	digitalWrite(rst_pin,LOW);
	delayMicroseconds(100);
	for (int i = 1; i <= num; i = i + 1) {
		digitalWrite(data_pin,HIGH);
		delayMicroseconds(100);
		digitalWrite(data_pin,LOW);
		delayMicroseconds(100);
	}
	while (digitalRead(busy_pin)) {}
}

/*
void VOICE68::disattach()        //引脚回收，恢复到上电状态
{
    digitalWrite(busy_pin,LOW);
    pinMode(rst_pin, OUTPUT);
	pinMode(data_pin, OUTPUT);

}
*/


bool VOICE68::isBusy()
{
	return digitalRead(busy_pin);
}